package com.bytedance.user.controller;


import com.bytedance.user.request.UserLogAndRegRequest;
import com.bytedance.user.request.UserRequest;
import com.bytedance.user.service.UserService;
import com.bytedance.user.respones.UserLogAndRegRespones;
import com.bytedance.user.respones.UserResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/douyin/user")
@Validated
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * /douyin/user/register/ - 用户注册接口
     * 新用户注册时提供用户名，密码，昵称即可，用户名需要保证唯一。创建成功后返回用户 id 和权限token.
     * 接口类型
     * POST
     * 接口定义
     *
     * @return
     */
    @PostMapping("/register")
    public UserLogAndRegRespones register(
            UserLogAndRegRequest userLogAndRegRequest
    ) {
        UserLogAndRegRespones userLogAndRegRespones = userService.register(userLogAndRegRequest);
        log.info(userLogAndRegRespones.toString());
        return userLogAndRegRespones;
    }

    /**
     * /douyin/user/login/ - 用户登录接口
     * 通过用户名和密码进行登录，登录成功后返回用户 id 和权限 token.
     * 接口类型
     * POST
     *
     * @return
     */
    @PostMapping("/login")
    public UserLogAndRegRespones login(
            UserLogAndRegRequest userLogAndRegRequest
    ) {
        UserLogAndRegRespones userLogAndRegRespones = userService.login(userLogAndRegRequest);
        log.info(userLogAndRegRespones.toString());
        return userLogAndRegRespones;
    }


    /**
     * /douyin/user/ - 用户信息
     * 获取登录用户的 id、昵称，如果实现社交部分的功能，还会返回关注数和粉丝数。
     * 接口类型
     * GET
     *
     * @return
     */
    @GetMapping()
    public UserResponses getUserInfo(UserRequest userRequest) {
        UserResponses userResponses = userService.getUserInfo(userRequest);
        return userResponses;
    }

}
